/**********************************************************************************
 * Copyright (c) 2012 - 2012,  parallel, All right reserved
 * Title: com.adc.parallel.constants  ThreadConstant.java 
 * @author shen  shenqiao2012@163.com 
 *  2012-11-20 下午7:04:48 
 *********************************************************************************/


package com.adc.parallel.constants;

import com.adc.quicktools.StringUtil;



/**
 * 
 * Description: define some static varable for thread
 * @author shen  shenqiao2012@163.com
 */
public class ThreadConstant {
	/**
	 * default thread success return info
	 */
	public final static int EXEC_SUCCESS=0;
	/**
	 * default thread fail return info
	 */
	public final static int EXEC_FAIL=-1;

	
	/**
	 * default executor thread run time
	 */
	private final static long Default_ExecutorTime=250L;
	/**
	 * default main thread sleep cycle
	 */
	private final static long Default_MainSleepTime=20*Default_ExecutorTime;
	/**
	 * default timer thread cycle
	 */
	private final static long Default_TimeGap=4*Default_ExecutorTime;
	/**
	 * default timer thread live time
	 */
	private final static long Default_MaxTime=10*Default_TimeGap;
	/**
	 * default timer thread cycle for clear complete
	 */
	private final static long Default_ClearComplete_TimeGap=2*Default_ExecutorTime;
	
	/**
	 * default timer thread cycle for receive task dto list
	 */
	private final static long Default_Receive_TimeGap=2*Default_ExecutorTime;
	
	/**
	 * per executor thread process time 
	 */
	private static long PerExecutorTime=SysConstants.Default_Value;
	/**
	 * the time gap between twice that push receive list to wait list
	 */
	private static long ReceiveTime=SysConstants.Default_Value;
	/**
	 * the time gap between twice that clear completed list which had been writen in log
	 */
	private static long ClearCompletedTime=SysConstants.Default_Value;
	/**
	 * the time gap of persistent 
	 */
	private static long PersistentCycle=SysConstants.Default_Value;
	/**
	 * the max alive time of persistent
	 */
	private static long PersistentMaxAliveTime=SysConstants.Default_Value;
	/**
	 * the time gap of main thread sleep
	 */
	private static long MainSleepTime=SysConstants.Default_Value;
	/**
	 * @return the perExecutorTime
	 */
	public static long getPerExecutorTime() {
		if (PerExecutorTime<0) {
			String temp=ConfigConstants.getConfig().getProperty(
					ConfigConstants.CFG_KEY_PerExecutorTime);
			if (StringUtil.checkStringValue(temp)) {
				PerExecutorTime=Long.parseLong(temp);
			}else {
				PerExecutorTime=Default_ExecutorTime;
			}
		}
		return PerExecutorTime;
	}
	/**
	 * @return the receiveTime
	 */
	public static long getReceiveTime() {
		if (ReceiveTime<0) {
			String temp=ConfigConstants.getConfig().getProperty(
					ConfigConstants.CFG_KEY_ReceiveTime);
			if (StringUtil.checkStringValue(temp)) {
				ReceiveTime=Long.parseLong(temp);
			}else {
				ReceiveTime=Default_Receive_TimeGap;
			}
		}
		return ReceiveTime;
	}
	/**
	 * @return the clearCompletedTime
	 */
	public static long getClearCompletedTime() {
		if (ClearCompletedTime<0) {
			String temp=ConfigConstants.getConfig().getProperty(
					ConfigConstants.CFG_KEY_ClearCompletedTime);
			if (StringUtil.checkStringValue(temp)) {
				ClearCompletedTime=Long.parseLong(temp);
			}else {
				ClearCompletedTime=Default_ClearComplete_TimeGap;
			}
		}
		return ClearCompletedTime;
	}
	/**
	 * @return the persistentCycle
	 */
	public static long getPersistentCycle() {
		if (PersistentCycle<0) {
			String temp=ConfigConstants.getConfig().getProperty(
					ConfigConstants.CFG_KEY_PersistentCycle);
			if (StringUtil.checkStringValue(temp)) {
				PersistentCycle=Long.parseLong(temp);
			}else {
				PersistentCycle=Default_TimeGap;
			}
		}
		return PersistentCycle;
	}
	/**
	 * @return the persistentMaxAliveTime
	 */
	public static long getPersistentMaxAliveTime() {
		if (PersistentMaxAliveTime<0) {
			String temp=ConfigConstants.getConfig().getProperty(
					ConfigConstants.CFG_KEY_PersistentMaxAliveTime);
			if (StringUtil.checkStringValue(temp)) {
				PersistentMaxAliveTime=Long.parseLong(temp);
			}else {
				PersistentMaxAliveTime=Default_MaxTime;
			}
		}
		return PersistentMaxAliveTime;
	}
	/**
	 * @return the mainSleepTime
	 */
	public static long getMainSleepTime() {
		if (MainSleepTime<0) {
			String temp=ConfigConstants.getConfig().getProperty(
					ConfigConstants.CFG_KEY_MainSleepTime);
			if (StringUtil.checkStringValue(temp)) {
				MainSleepTime=Long.parseLong(temp);
			}else {
				MainSleepTime=Default_MainSleepTime;
			}
		}
		return MainSleepTime;
	}
	
}
